package thread.concurrents;

import java.util.Arrays;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * @Author: ycy
 * @CreateDate: 2019/10/22 15:32
 */
public class ProductCustomDemo {

  //生产 消费
  public static void main(String[] args) {

    String[] typeNames = {"1","2","4"};


    String[] newTypeNames = new String[typeNames.length - 1];
    System.arraycopy(typeNames, 1, newTypeNames, 0, typeNames.length-1);

    System.out.println(Arrays.toString(newTypeNames));

    ArrayBlockingQueue<String> arrayBlockingQueue = new ArrayBlockingQueue(2);

    //生产
    Thread product = new Thread() {
      @Override
      public void run() {
        int count = 0;
        while (true) {
          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          try {
            String e = (++count) + "号";
            System.out.println(e);
            arrayBlockingQueue.put(e);


          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    };
    product.start();

//    //消费
//    Thread custom = new Thread() {
//      @Override
//      public void run() {
//        while (true) {
//          try {
//            Thread.sleep(4000);
//          } catch (InterruptedException e) {
//            e.printStackTrace();
//          }
//          String take = null;
//          try {
//            take = arrayBlockingQueue.take();
//            System.out.println("消费" + take);
//          } catch (InterruptedException e) {
//            e.printStackTrace();
//          }
//        }
//      }
//    };
//    custom.start();


  }

}
